package com.aijk.ehm.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;

import com.aijk.ehm.dao.mybatis.EhmPeopleCrowdMapper;
import com.aijk.ehm.model.EhmPeopleCrowd;
import com.aijk.ehm.model.EhmPeopleCrowdExample;
import com.aijk.ehm.model.qo.EhmPeopleCrowdQo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EhmPeopleCrowdService {
    private static Logger logger = LoggerFactory.getLogger(EhmPeopleCrowdService.class);

    @Autowired
    private EhmPeopleCrowdMapper mapper;

    public EhmPeopleCrowdExample getExample(EhmPeopleCrowdQo qo) {
        EhmPeopleCrowdExample example = new EhmPeopleCrowdExample();
        EhmPeopleCrowdExample.Criteria criteria = example.createCriteria();
        if (qo != null) {
            if (Utils.isNotEmpty(qo.getSortway())) example.setOrderByClause(qo.getSortway());
            if (Utils.isNotEmpty(qo.getNid())) criteria.andIdNotEqualTo(qo.getNid());
            if (Utils.isNotEmpty(qo.getNids())) criteria.andIdNotIn(qo.getNids());
        }
        return example;
    }

    public int count(EhmPeopleCrowdQo qo) {
        return mapper.countByExample(getExample(qo));
    }

    public int save(EhmPeopleCrowd bean) {
        return mapper.insertSelective(bean);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int update(EhmPeopleCrowd bean) {
        return mapper.updateByPrimaryKeySelective(bean);
    }

    public EhmPeopleCrowd findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<EhmPeopleCrowd> find(EhmPeopleCrowdQo qo) {
        return mapper.selectByExample(getExample(qo));
    }

    public PageInfo<EhmPeopleCrowd> page(PagingRequest pagingRequest, EhmPeopleCrowdQo qo) {
        PageHelper.startPage(pagingRequest.getPageNum() , pagingRequest.getPageSize());
        return new PageInfo<EhmPeopleCrowd>(mapper.selectByExample(getExample(qo)));
    }
}